#
# Makefile for PF_RING MOD INVEATECH
#

#
# GCC march/mtune
#
GCCARCH = #corei7 corei7-avx core-avx2
ifneq ($(strip $(GCCARCH)), )
  ARCHFLAGS = -march=$(GCCARCH) -mtune=$(GCCARCH)
  LIBARCH = _$(GCCARCH)
endif

#
# Installation directory
#
INSTDIR   = /usr/local

#
# Search directories
#
INCLUDE  = -I../../../kernel -I../../nbpf -I../../lib

#
# Object files
#
SRCS      = pfring_mod_invea.c 
OBJS      = pfring_mod_invea.o
MACHINE   = $(shell uname -m)

#
# C compiler and flags
#
CC        = ${CROSS_COMPILE}gcc $(ARCHFLAGS) -O2 #-g
CFLAGS    = -Wall -fPIC ${INCLUDE} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
LDFLAGS   = -shared

SYSLIBS   = -lpthread

#SYSLIBS="$SYSLIBS -lsze2"

# How to make an object file
%.o: %.c %.h Makefile ../../../kernel/linux/pf_ring.h ../../lib/pfring.h
	${CC} ${CFLAGS} -c $< -o $@

#
# Main targets
#
STATICLIB  = ../../lib/libs/libpfring_invea_$(MACHINE)$(strip $(LIBARCH)).a
DYNAMICLIB = ../../lib/libs/libpfring_invea_$(MACHINE).so
TARGETS    = ${STATICLIB} ${DYNAMICLIB}

default: ${TARGETS}

${STATICLIB}: ${OBJS}
	@echo "=*= making library $@ =*="
	ar rs $@ ${OBJS} pfring_mod_invea.h
	ranlib $@

${DYNAMICLIB}: ${OBJS}
	@echo "=*= making library $@ =*="
	${CC} ${LDFLAGS} ${OBJS} ${SYSLIBS} -o $@

all: install

install:
	make clean; make GCCARCH="corei7"
	make clean; make GCCARCH="corei7-avx"
	make clean; make GCCARCH="core-avx2"
	make clean; make GCCARCH=""

clean:
	@rm -f *.o *~ *.so *.a

depend: .depend

.depend: $(SRCS)
	rm -f ./.depend
	$(CC) $(CFLAGS) -MM $^>>./.depend;

include .depend
